package com.xxx.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: xxx
 * @Date: 2023/1/9 21:41
 * @Description: RabbitMq配置类-header
 */
@Configuration
public class RabbitMQHeaderConfig {
    
    private static final String QUEUE01="queue_header01";
    private static final String QUEUE02="queue_header02";
    private static final String EXCHANGE="headersExchange";

    /**
     * 准备队列
     */
    @Bean
    public Queue queue00001(){
        return new Queue(QUEUE01);
    }

    /**
     * 准备队列
     */
    @Bean
    public Queue queue00002(){
        return new Queue(QUEUE02);
    }

    /**
     * 准别交换机
     */
    @Bean
    public HeadersExchange headersExchange(){
        return new HeadersExchange(EXCHANGE);
    }

    /**
     * 绑定
     */
    @Bean
    public Binding binding00001(){
        Map<String,Object> map=new HashMap<>();
        map.put("color","red");
        map.put("speed", "low");
        return BindingBuilder.bind(queue00001()).to(headersExchange()).whereAny(map).match();
    }

    /**
     * 绑定
     */
    @Bean
    public Binding binding00002(){
        Map<String,Object> map=new HashMap<>();
        map.put("color","red");
        map.put("speed", "fast");
        return BindingBuilder.bind(queue00002()).to(headersExchange()).whereAll(map).match();
    }
}
